{include file="public/header"/}
<link rel="stylesheet" href="/public/static/admin/easyui/layui-v2.6.8/css/layui.css">
<link rel="stylesheet" type="text/css" href="/public/static/admin/easyui/jeasyui/themes/icon.css">
<style>
	.matchCon {
		width: 280px;
	}

	.chk-list {
		line-height: 28px;
	}

	.url-box {
		height: 28px;
		line-height: 28px;
		cursor: pointer;
	}

	.url-box a {
		margin-right: 5px;
	}

	.layui-input,
	.layui-select,
	.layui-textarea {
		height: 30px;
	}

	.ul-inline li i {
		padding: 0;
	}

	.layui-form-checked[lay-skin=primary] i {
		border-color: #4dc2e6 !important;
		background-color: #4dc2e6;
	}

	.layui-form-select dl {
		max-height: 192px !important;
	}
</style>

<div class="bill-ser-top">
	<ul class="ul-inline cf layui-form">

		<!-- 选择客户类别 -->
		{include file="admin@select/customer_category"/}

		<li>
			<input type="text" id="matchCon" class="ui-input matchCon ui-input-ph" value=""
				placeholder="输入客户编号/ 名称/ 联系人/ 电话/ 送货地址/ 备注查询" style="font-size: 12px;">
		</li>

		<li class="chk-list" id="chk-isZero" style="display: list-item;">
			<input type="checkbox" value="1" name="is_default" lay-skin="primary" id="" title="包含销售人员查询">
		</li>
		<li class="chk-list" id="chk-isNearPrice" style="display: list-item;">
			<input type="checkbox" value="1" name="is_default" lay-skin="primary" id="isNearPrice" title="显示禁用客户">
		</li>
		<li><a class="ui-btn ui-btn-search" id="search">查询</a></li>
		<li class="url-box" id="openUrl">
			<!-- <a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1547#pid=5693" target="_blank" class="video-icon"></a>商品管理 -->
		</li>
	</ul>
</div>


<!-- 选择客户类别树 -->
{include file="admin@popup/customer_category"/}



<div class="wrapper btc">
	<div class="ui-config-box">
		<span id="config" class="ui-config">
			<a href="#" class="ui-icon-config-new"></a>
			列设置
		</span>
	</div>

	<div class="bill-ser-botm cf">
		<div class="fr ml10">
			<a href="#" class="ui-btn-bill ui-btn-add mrb" id="btn-add"
				onclick="lopen('add.html','新增', '690px', '710px')">新增</a>
			<a class="ui-btn-bill mrb" id="btn-disable" onclick="lopen('address.html','联系地址', '690px', '450px')">禁用</a>
			<a class="ui-btn-bill mrb" id="btn-enable">启用</a>
			<!--<a href="#" class="ui-btn mrb" id="btn-print">打印</a>-->
			<a href="#" class="ui-btn-bill mrb" id="btn-import">导入</a>
			<a class="ui-btn-bill mrb" id="btn-export">导出</a>
			<a href="#" class="ui-btn-bill" id="btn-batchDel">删除</a>
		</div>
	</div>
	<div class="grid-wrap">
		<table id="grid">
		</table>
		<div id="page"></div>
	</div>
</div>

<script src="/public/static/admin/easyui/layui-v2.6.8/layui.js"></script>
<script type="text/javascript" src="/public/static/admin/easyui/jeasyui/jquery.easyui.min.js"></script>
<script type="text/javascript">

	function lopen(url, title, width, height) {
		layer.open({
			type: 2,
			title: title,
			shadeClose: true,
			shade: 0.3,
			maxmin: true, //开启最大化最小化按钮
			btn: ['确定', '取消'],
			area: [width, height],
			content: url,
			yes: function (index, layero) {
				var body = layer.getChildFrame('body', index);
				var customer_basedata1 = body.find('#manage-form').serialize();
				var customer_basedata2 = body.find('#manage-form-mark').serialize();
				var customer_basedata = customer_basedata1 + "&" + customer_basedata2;

				customer_basedata = unserialize(customer_basedata);

				var customer_extdata = body.find('#grid').jqGrid('getGridParam', 'data');
				// 刷新表格值
				body.find("#reloadTable").click();

				$.ajax({
					type: 'POST',
					url: "save.html",
					data: { customer_basedata: customer_basedata, customer_extdata: customer_extdata },
					dataType: "json",
					async: false,
					error: function (request) {
						alert("发送请求失败！");
					},
					success: function (data) {
						if (data.status == 1) {
							layer.msg(data.msg);
							layer.close(index);
							reload();
						} else {
							layer.msg(data.msg);
						}
					}
				});
			}
		});
	}

	//$(function(){
	$(document).ready(function () {

		// 点击查询按钮
		$("#search").click(function () {
			var category_id = $('#customer_category_id').val();
			var keywork = $('#matchCon').val();

			//此处可以添加对查询数据的合法验证 
			$("#grid").jqGrid('setGridParam', {
				datatype: 'json',
				postData: {
					ajax: 100,
					category_id: category_id,
					keywork: keywork
				}, //发送数据 
				page: 1
			}).trigger("reloadGrid"); //重新载入 
		});

		//alert("1111");
		$("#grid").jqGrid({
			url: '/admin/customer/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: ["操作", "客户类别", "客户等级", "客户编号", "客户名称", "销售人员", "联系人", "纳税人识别号", "开户银行", "银行账号", "手机", "座机", "QQ/微信/邮箱", "应收款余额", "送货地址", "备注", "已授权用户", "状态"],
			colModel: [
				{ name: 'id', index: 'id', width: 60, formatter: cLink },
				{ name: 'category', index: 'name asc', width: 100 },
				{ name: 'vip', index: 'name asc', width: 100 },
				{ name: 'sn', width: 100 },
				{ name: 'name', index: 'name asc', width: 120 },
				{ name: 'staff', index: 'staff asc', width: 120 },
				{ name: 'username', index: 'name asc', width: 80 },
				{ name: '', index: 'name asc', width: 100, lable: "纳税人识别号" },
				{ name: '', index: 'name asc', width: 80, lable: "开户银行" },
				{ name: '', index: 'name asc', width: 80, lable: "银行账号" },

				{ name: 'telephone', index: 'name asc', width: 100 },
				{ name: 'phone', index: 'name asc', width: 100 },
				{ name: 'numbers', index: 'name asc', width: 120 },
				{ name: 'recive_money', index: 'name asc', width: 100 },
				{ name: 'address', index: 'name asc', width: 200 },
				{ name: 'mark', index: 'name asc', width: 200 },
				{ name: 'user', index: 'name asc', width: 200 },
				{ name: 'status', index: 'name asc', formatter: cStatus, width: 80 },
			],
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置
			multiselect: true,
			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			}
		});

		function cLink(cellvalue, options, rowObject) {
			return '<div class="operating"><span class="ui-icon ui-icon-pencil" onclick="lopen(\'edit.html?id=' + rowObject.id + '\',\'编辑\',\'690px\',\'710px\')" title="修改"></span><span class="ui-icon ui-icon-trash" onclick="del(' + rowObject.id + ')" title="删除"></span></div>'
		}

		function cStatus(cellvalue, options, rowObject) {
			if (rowObject.status == 0) {
				return '<span class="set-status open" data-delete="false" onclick="switchs(this,' + rowObject.id + ')"><span class="ui-icon-circle"></span></span>';
			} else {
				return '<span class="set-status close" data-delete="false" onclick="switchs(this,' + rowObject.id + ')"><span class="ui-icon-circle"></span></span>';
			}

		}
	});

	function switchs(obj, id) {
		if ($(obj).hasClass("open")) {
			$(obj).removeClass("open");
			$(obj).addClass("close");
			status = 1;
		} else {
			$(obj).removeClass("close");
			$(obj).addClass("open");
			status = 0;
		}

		$.ajax({
			type: 'POST',
			url: "status.html",
			data: { id: id, status: status },
			dataType: "json",
			async: false,
			error: function (request) {
				layer.msg("发送请求失败！");
			},
			success: function (data) {
				if (data.status == 1) {
					layer.msg(data.msg);
				} else {
					layer.msg(data.msg);
				}

			}
		});
	}

</script>


{include file="public/footer"/}